package com.kinyx.framework.db.dialect;

import java.util.List;

import com.kinyx.framework.db.sentence.str.SQL;

public class Oracle extends Dialect {

	@Override
	public boolean checkDriverClassName(final String driverClassName) {
		return "oracle.jdbc.driver.OracleDriver".equals(driverClassName);
	}

	@Override
	public SQL createPageSQL(final String sql, final List<Object> params, int pageNumber, int pageSize) {
		// 参数修正
		if (pageNumber < 0) { pageNumber = 0; }
		if (pageSize <= 0) { pageSize = com.kinyx.framework.Configs.default_pageSize; }
		// 拼接
		return new SQL().addAll(params).s("SELECT * FROM (SELECT X.*, ROWNUM AS R FROM (").s(sql).s(") X WHERE ROWNUM <= ?) WHERE R >= ?").p((pageNumber + 1) * pageSize).p((pageNumber * pageSize) + 1);
	}

}
